package cevent.source.cloudcenter.server.util;/**
 * Created by Cevent on 2021/3/20.
 */

import cevent.source.cloudcenter.server.exception.ValidatorException;
import org.springframework.util.StringUtils;


/**
 * @author cevent
 * @description 后端校验工具类
 * @date 2021/3/20 9:06
 */
public class ValidatorUtil {
    //1.非空判断，避免big decimal报错，这里更改为object
    public static void requiredEmpty(Object str,String fieldName){
        if(StringUtils.isEmpty(str)){
            throw new ValidatorException(fieldName+"不能为空");
        }
    }
    //2.长度校验
    public static void requiredLength(String str,String fieldName,int min,int max){
        int length=0;
        if(!StringUtils.isEmpty(str)){
            length=str.length();
        }
        if(length<min || length>max){
            throw new ValidatorException(fieldName+"长度 "+min+" ~ "+max+"位");
        }
    }
}
